package cn.smile.controller.notebook;

import cn.smile.bean.dto.notebook.NotebookDTO;
import cn.smile.bean.form.notebook.AddNotebookForm;
import cn.smile.bean.form.notebook.QueryNotebookForm;
import cn.smile.bean.form.notebook.UpdateNotebookForm;
import cn.smile.business.notebook.INotebookService;
import cn.smile.commons.response.MyResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/notebook")
public class NotebookController {

    @Resource
    private INotebookService service;

    @PostMapping(value = "addNotebook")
    public MyResult<Boolean> addNotebook(@Valid @RequestBody AddNotebookForm form) {
        return MyResult.OK(service.addNotebook(form));
    }

    @PostMapping(value = "updateNotebook")
    public MyResult<Boolean> updateNotebook(@Valid @RequestBody UpdateNotebookForm form) {
        return MyResult.OK(service.updateNotebook(form));
    }

    @PostMapping(value = "query/page")
    public MyResult<IPage<NotebookDTO>> getPage(@RequestBody QueryNotebookForm form) {
        return MyResult.OK(service.getPage(form));
    }

    @GetMapping(value = "getById")
    public MyResult<NotebookDTO> getById(@RequestParam("id") String id) {
        return MyResult.OK(service.getEntityById(id));
    }

    @GetMapping(value = "delNotebook")
    public MyResult<Boolean> delNotebook(@RequestParam("id") String id) {
        return MyResult.OK(service.delEntity(id));
    }
}
